<?php
class DirList{
	function ReadFolderDirectory($dir = "root_dir/here")
    {
        $listDir = array();
        if($handler = opendir($dir)) {
            while (($sub = readdir($handler)) !== FALSE) {
                if ($sub != "." && $sub != ".." && $sub != "Thumb.db") {
                    if(is_file($dir."/".$sub)) {
                        $listDir[] = $sub;
                    }elseif(is_dir($dir."/".$sub)){
                        $listDir[$sub] = $this->ReadFolderDirectory($dir."/".$sub);
                    }
                }
            }   
            closedir($handler);
        }
        return $listDir;   
    } 
}
	$dir = new DirList();
	$dirList = $dir->ReadFolderDirectory('./userfiles/ron0914');
	$dates = array_keys($dirList);
	//echo '<pre>'; print_r($dirList); echo '</pre>';
	/*
	var events = [
    { "EventID": 1, "StartDate": new Date(2009, 1, 12), "Title": "10:00 pm - EventTitle1", "URL": "#", "Description": "This is a sample event description", "CssClass": "Birthday" },
    { "EventID": 2, "Date": "2009-02-28T00:00:00.0000000", "Title": "9:30 pm - this is a much longer title", "URL": "#", "Description": "This is a sample event description", "CssClass": "Meeting" },
];
	*/
	$eventsJsonString = '[';
	foreach($dates as $key=>$date){
		$year = date('Y',strtotime($date));
		$month = date('m',strtotime($date))-1; //stupid javascript month from 0
		$day = date('d',strtotime($date));
		
		foreach($dirList[$date] as $id=>$table){
			
		$event = '{ "EventID" : '.($id+1).', "StartDate" : new Date('.$year.', '.$month.', '.$day.'), "Title": "'.str_replace('.txt','',$table).'", "URL" : "handHistory.php?date='.$date.'&table='.urlencode($table).'", "Description" : "'.str_replace('.txt','',$table).'", "CssClass" : ""},';
		$eventsJsonString .= $event;
		
		}
		
	}
	$eventsJsonString = substr($eventsJsonString,0,-1);
	$eventsJsonString .= ']';
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Hand Analyser</title>
<link REL="SHORTCUT ICON" HREF="http://ron.motionlabclients.co.uk/pkrHands/favicon.ico">

<link rel="stylesheet" type="text/css" href="views/themes/default/css/jquery-ui/theme/ui.all.css">
<link rel="stylesheet" type="text/css" href="app/webroot/css/core.css">

<style type="text/css">
td.weekend{ background-color: #6CF;}
</style>


<script src="http://www.google.com/jsapi?key=ABQIAAAAdbZzzW6_p1p1VZBkc9LxYhQRazRz_hx3HcUsGZHFt1z3iV6UMhQyhI0iG0NiX4N6bc6haD8-jdJPyg" type="text/javascript"></script>
<script type="text/javascript">
		var initJquery = function(){google.load("jquery", "1.2");
		google.load("jqueryui", "1.5");
		} ; 
		try {initJquery(); } catch (e){ setTimeout("1000" , initJquery ); }
</script>
<script src="app/webroot/js/jquery-jMonthCalendar-plugin.js"></script>
<script>
	$('document').ready(function(){
		var options = { };
		var events = <?php echo $eventsJsonString; ?>;
		$.jMonthCalendar.Initialize(options, events);
	});
</script>
</head>

<body>
<div id="jMonthCalendar"></div>
<div style="clear: both">&nbsp;</div>
</body>
</html>